How to terminate all [grand]child processes using C# on WXP (and newer MSWindows)
Posted
by NVRAM
on Stack Overflow
See other posts from Stack Overflow
or by NVRAM
Published on 2009-07-16T16:02:42Z
Indexed on
2010/03/09
9:21 UTC
Read the original article
Hit count: 384
Question: How can I determine all processes in the child's Process Tree to kill them?
I have an application, written in C# that will:
- Get a set of data from the server,
- Spawn a 3rd party utility to process the data, then
- Return the results to the server.
This is working fine. But since a run consumes a lot of CPU and may take as long as an hour, I want to add the ability to have my app terminate its child processes.
Some issues that make the simple solutions I've found elsewhere are:
- My app's child process "A" (InstallAnywhere EXE I think) spawns the real processing app "B" (a java.exe), which in turns spawns more children "C1".."Cn" (most of which are also written in Java).
- There will likely be multiple copies of my application (and hence, multiple sets of its children) running on the same machine.
- The child process is not in my control so there might be some "D" processes in the future.
- My application must run on 32-bit and 64-bit versions of MSWindows.
On the plus side there is no issue of data loss, a "clean" shutdown doesn't matter as long as the processes end fairly quickly.
© Stack Overflow or respective owner